package com.example.pay.controller;

import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.example.common.domain.Result;
import com.example.pay.domain.dto.PayDTO;
import com.example.pay.service.PaymentService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/pay")
@RequiredArgsConstructor
public class PayController {
    private final PaymentService payService;


    @PostMapping
    public Result<Object> payOrder(@RequestBody PayDTO payDTO) {
        log.info("支付订单:{}", payDTO);
        Object response = payService.processPayment(payDTO);
        return Result.success(response);
    }

    /**
     * 支付宝异步回调
     */
    @PostMapping("/alipay/notify")
    public Result handleNotify(HttpServletRequest request) {
        String tradeStatus = request.getParameter("trade_status");
        String outTradeNo = request.getParameter("out_trade_no");
        return null;

    }

}
